import axios from 'axios/index'
//axios.defaults.baseURL="http://frp.voidgeek.com:7005/frbe/"
var baseURL="http://localhost:8080/frbe/"
axios.defaults.baseURL=baseURL
axios.defaults.withCredentials = true
class ApiCaller {
    call({url,
             method = 'GET', body = null,params=null
         }) {
        let p = new Promise(
            (resolve, reject) => {
                axios.request({
                    method: method,
                    url: url,
                    data:body,
                    params:params
                }).then(function (response) {

                    let myResponse = {
                        // 服务端返回的数据
                        data: response.data,
                        // 服务端返回的状态码
                        status: response.status,
                        // 服务端返回的状态信息
                        statusText: response.statusText,
                        // 响应头
                        // 所有的响应头名称都是小写
                        headers: response.headers
                    }
                    resolve(myResponse);
                }).catch(
                    function (error) {
                        // let response = error.response;
                        // let myResponse = {data:null,status:null,statusText:null,
                        // headers:null// 所有的响应头名称都是小写
                        // }
                        // if(null!=response)
                        // {
                        //   myResponse.data=response.data
                        //   myResponse.status=response.status
                        //   myResponse.statusText=response.statusText
                        //   myResponse.headers=response.headers
                        // }
                        // let myErr = { response: myResponse }
                        reject(error)
                    });
            }
        )

        return p;
    }
}
export default new ApiCaller()
export {
    baseURL
}